'use strict';

define(['services'], function (services) {
    services.solr.register('CollectionService', ['$resource', function ($resource) {
        var resource = $resource('/rest/solr/collection/:id', {id: '@id'}, {
            query: {
                isArray: false
            },
            'reload': {
                url: '/rest/solr/collection/:id/reload',
                method: 'GET',
                params: {id: '@id'},
                isArray: false
            },
            'optimize': {
                url: '/rest/solr/collection/:id/optimize',
                method: 'GET',
                params: {id: '@id'},
                isArray: false
            }
        });
        resource.exist = function (name, idNo) {
            var exist = false;
            $.ajax({
                type: 'get',
                url: '/rest/solr/collection/exist',
                async: false,
                data: {
                    name: name,
                    idNo: idNo
                },
                success: function (res) {
                    exist = (res == 'true' || res);
                }
            });
            return exist;
        };
        return resource;
    }]);
});